type TypeListItem = {
	label: string;
	value: string | number;
	color?: string;
	[key: string]: any;
};

type TypeObject = {
	[key: string]: TypeListItem;
};

export const BUSINESS_CONSTANTS = [];

export const AuthenticationType = {
	ENTERPRISE: {
		label: '企业',
		value: '1',
		icon: 'icon-enterprise'
	},
	SCHOOL: {
		label: '学校',
		value: '2',
		icon: 'icon-school'
	},
	CERTIFICATION: {
		label: '认证机构',
		value: '3',
		icon: 'icon-certification'
	},
	OTHER: {
		label: '其他',
		value: '4',
		icon: 'icon-other'
	}
};

export const ApproveType = {
	COMPANY: {
		label: '机构入驻',
		value: '1',
		icon: 'icon-enterprise'
	},
	USER: {
		label: '企业成员注册',
		value: '2',
		icon: 'icon-school'
	}
};
/** 认证相关的分类 */
export const ClassificationType: TypeObject = {
	AREA: {
		label: '区域',
		value: 1,
		tag: 'AREA'
	},
	AUTHENTICATION_PROJECT: {
		label: '认证项目',
		value: 2,
		tag: 'AUTHENTICATION_PROJECT'
	},
	OBJECT_BIG_CLASS: {
		label: '对象大类',
		value: 3,
		tag: 'OBJECT_BIG_CLASS'
	},
	OBJECT_SMALL_CLASS: {
		label: '对象小类',
		value: 4,
		tag: 'OBJECT_SMALL_CLASS'
	},
	STANDARD: {
		label: '标准',
		value: 5,
		tag: 'STANDARD'
	}
};

/** 认证状态的类型 */
export const AuthenticationStatusType: TypeObject = {
	WAITING_FOR_AUTHENTICATION: {
		label: '待审核',
		value: 0,
		color: '#FFC107'
	},
	AUTHENTICATED: {
		label: '通过',
		value: 1,
		color: '#4CAF50'
	},
	REJECTED: {
		label: '未通过',
		value: 2,
		color: '#F44336'
	}
};

/** 公告的优先级 */
export const PriorityType: TypeObject = {
	GENERAL: {
		label: '普通',
		value: 0
	},
	IMPORTANT: {
		label: '重要',
		value: 1
	}
};

/** 是否定向申请 */
export const ApplyDirectionalType: TypeObject = {
	GENERAL: {
		label: '定向申请',
		value: 1
	},
	IMPORTANT: {
		label: '非定向申请',
		value: 2
	}
};

/** 消息发送类型 */
export const senderMessageType: TypeObject = {
	GENERAL: {
		label: '用户',
		value: 1
	},
	IMPORTANT: {
		label: '系统',
		value: 2
	}
};

/** 应用类型 */
export const AppInfoTypeList: TypeObject = {
	OFFICIAL: {
		label: '官方',
		value: 0
	},
	SELF_BUILD: {
		label: '自建',
		value: 1
	}
};

/** 用户的启用状态 */
export const IsEnableType: TypeObject = {
	ENABLE: {
		label: '启用',
		value: 0
	},
	DISABLE: {
		label: '禁用',
		value: 1
	}
};

/** 用户类型 */
export const UserType: TypeObject = {
	ADMIN: {
		label: '门户管理员',
		value: 1
	},
	ORGANIZATION_ADMIN: {
		label: '机构管理员',
		value: 2
	},
	ORGANIZATION_USER: {
		label: '机构用户',
		value: 3
	}
};

/** 机构申请状态 */
export const EnterpriseApplyType: TypeObject = {
	WAITING_FOR_RECEIVE: {
		label: '待接收',
		value: 0,
		color: '#FFC107'
	},
	ORGANIZATION_ADMIN: {
		label: '已接收',
		value: 1,
		color: '#4CAF50'
	},
	ORGANIZATION_USER: {
		label: '已撤销',
		value: 2,
		color: '#F44336'
	}
};

/** 行业新闻来源 */
export const IndustrySourceType: TypeObject = {
	INTERNAL: {
		label: '站内',
		value: 0
	},
	SPIDER: {
		label: '爬虫',
		value: 1
	}
};
/** 审批状态 */
export const ApproveStatusYesNoType: TypeObject = {
	APPROVED: {
		label: '通过',
		value: 1,
		color: '#4CAF50'
	},
	REJECTED: {
		label: '未通过',
		value: 2,
		color: '#F44336'
	}
};

/** 审批状态 */
export const ApproveStatusType: TypeObject = {
	WAITING_FOR_APPROVE: {
		label: '待审批',
		value: 0,
		color: '#FFC107'
	},
	...ApproveStatusYesNoType
};

/** 对象转数组 */
export const objToArray = (enumObj: Record<string, TypeListItem>) => {
	// 创建一个空数组
	const arr: TypeListItem[] = [];

	// 遍历枚举对象
	for (const key in enumObj) {
		if (Object.hasOwn(enumObj, key)) {
			const item = enumObj[key];
			// 将枚举对象中的每个属性转换为键值对对象，并添加到数组中
			arr.push(item);
		}
	}

	return arr;
};

/** 根据值获取枚举对象的 label */
export const getEnumLabel = (
	enumObj: Record<string, TypeListItem>,
	value: string | number,
	defaultValue: string | number = ''
) => {
	for (const key in enumObj) {
		if (Object.hasOwn(enumObj, key)) {
			const item = enumObj[key];
			if (item.value == value) {
				return item.label;
			}
		}
	}
	return defaultValue;
};

/** 根据值获取枚举对象的 label */
export const getEnumItem = (
	enumObj: Record<string, TypeListItem>,
	value: string | number,
	defaultValue = {} as TypeListItem
) => {
	for (const key in enumObj) {
		if (Object.hasOwn(enumObj, key)) {
			const item = enumObj[key];

			if (item.value == value) {
				return item;
			}
		}
	}
	return defaultValue;
};
